import 'package:daoyi_admin_ui_getx/app/modules/auth/controllers/auth_controller.dart';
import 'package:daoyi_admin_ui_getx/app/routes/app_pages.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/tabs_controller.dart';

class TabsView extends GetView<TabsController> {
  const TabsView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          // appBar: AppBar(
          //   title: const Text('TabsView'),
          //   centerTitle: true,
          // ),
          body: controller
              .bottomNavigationBar[controller.currentIndex.value].page,
          bottomNavigationBar: BottomNavigationBar(
            items: controller.bottomNavigationBar
                .map<BottomNavigationBarItem>((item) => item.item)
                .toList(),
            currentIndex: controller.currentIndex.value,
            type: BottomNavigationBarType.fixed,
            selectedItemColor: Colors.red,
            onTap: (index) {
              if (kDebugMode) {
                print(index);
              }
              if (!Get.find<AuthController>().isLogin()) {
                Get.offNamed(Routes.LOGIN);
                return;
              }
              //步骤3新增：将当前选中的赋值给变量
              controller.setCurrentIndex(index);
            },
          ),
        ));
  }
}
